home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / QF2.ZIP / QF.DOC < prev    next >
Text File  |  1995-04-10  |  12KB  |  298 lines

  1.                      Quickfire: The Reincarnation
  2.                            by Diana Gruber
  3.  
  4. This is the second release of Quickfire. The original beta version
  5. of Quickfire was released in 1993 as a demo of a graphics library
  6. and a sound toolkit. The file was called "QF01B.ZIP", that's "B for
  7. Beta", meaning the program was not finished. I always intended to
  8. finish the program and turn it into a game, but I never got around
  9. to it. So poor Quickfire circulated in a state of perpetual beta
  10. for the past two years.
  11.  
  12. Many people have asked me to release the source code for Quickfire.
  13. I have not done up until this point for several reasons. First, there
  14. was the problem with the sound and music libraries. Originally,
  15. Quickfire was released with beautiful music by Rob Wallace, and John
  16. Ratcliff generously provided the drivers to play the music. The source
  17. code to rebuild Quickfire would require linking with John Ratcliff's
  18. code. Since I didn't have his permission to distribute his libraries
  19. with Quickfire (and since it would have added considerable size to
  20. the distribution if I did) I delayed the release.
  21.  
  22. Also, I kept thinking I was going to turn Quickfire into a "real"
  23. game. It is such a pretty little shooter, it deserves to move beyond
  24. the demo phase. I don't know if that will ever happen, but at this
  25. point in my busy life, I think if anybody is going to create a real
  26. game with Quickfire, it will be someone other than me. (Feel free
  27. to try, just please talk to me before you release it. The code is
  28. still copyrighted, but I'm real open to working with other developers
  29. on this. Let's talk.)
  30.  
  31. So why am I releasing the Quickfire source code now? 
  32.  
  33. Mainly for intellectual curiosity. There has been a debate for some
  34. time on the best way to do 8-directional fast scrolling in an arcade
  35. game. Is it better to build screens in video memory and use a mode X
  36. page-flipping technique, or does it work better if you build the
  37. screens in RAM and blast them to the screen in mode 13h? I decided to
  38. try it both ways and see. The enclosed code accomplishes the
  39. scrolling using two different methods. Results are listed below.
  40.  
  41. Installing and Running Quickfire
  42. --------------------------------
  43.  
  44. Just copy it into a subdirectory. This is not a very complicated
  45. program. The music and sound has been stripped out to simplify it
  46. even more. The files you need to run the program are as follows:
  47.  
  48.  QF13H.EXE -- mode 13h version of Quickfire
  49.  QFX.EXE   -- mode X version of Quickfire
  50.  QF.PCX    -- background tiles
  51.  QF1.PCX   -- title screen
  52.  QF.BMP    -- sprite bitmaps
  53.  QF.LEV    -- level map data
  54.  
  55. Run either one of the EXE files to see Quickfire. On exit, the frame
  56. rate will be displayed on the screen. Quickfire will run in self-play
  57. demo mode unless you press a key. The following keys will control
  58. Quickfire:
  59.  
  60.  UP, DOWN, LEFT, RIGHT -- move around
  61.  CTRL -- shoot
  62.  ESC  -- QUIT
  63.  
  64. Pressing two keys together, for example UP and LEFT, will cause 
  65. Quickfire to "roll".
  66.  
  67. In general, the program runs too fast to be playable.
  68.  
  69. Programming Considerations
  70. --------------------------
  71.  
  72. The source code exists in the following three files:
  73.  
  74.  QF.C      -- animation functions and function main
  75.  LOADGAME.C-- initialization, termination, etc.
  76.  DEFS.H    -- global declarations and definitions
  77.  
  78. Quickfire requires Fastgraph 4.0 to link. If you have Fastgraph/Light
  79. 4.02, you can relink Quickfire in real mode only, which means you can
  80. only use the mode X method. If you have an earlier version of
  81. Fastgraph or Fastgraph/Light, you can re-link in real mode, but you
  82. need to remove the call to fg_initpm().
  83.  
  84. I compiled the code in Watcom 10.0, using the DOS4GW DOS extender
  85. from Rational Systems (now Tenberry). It should work with other
  86. compilers and DOS extenders as well. I linked with Fastgraph 4.02. 
  87.  
  88. For those who want to compare results with out recompiling and
  89. relinking, I included EXE files for the program both ways. QF13H.EXE
  90. shows the program in mode 13h and QFX.EXE shows the program in
  91. mode X. If you rebuild the program, I suggest you call it simply
  92. qf.exe. I have included a batch file
  93.  
  94.  WCR.BAT
  95.  
  96. To build the program with Watcom C. I also included a file called
  97.  
  98.  WORK
  99.  
  100. Which works with the Microsoft Make utility to build files with
  101. the Microsoft C compiler (real mode only). If you want to compile
  102. with Borland, you will need to make a project file. You can do
  103. that yourself, just add the two source code files and the Fastgraph
  104. library.
  105.  
  106. Two Strategies in One Program
  107. -----------------------------
  108.  
  109. Experimenting with various video modes and blitting strategies is
  110. very easy with Fastgraph. There is no need to suffer the headache
  111. of rewriting the low-level code from scratch, knowing that half of
  112. what you write is going to be thrown out before the final product
  113. is released. Fastgraph allows you to prototype a game several ways
  114. and choose the preferred method.
  115.  
  116. This is especially important in a case like this where there is no
  117. "right" or "wrong" way to write the program. While one method may
  118. sound more appealing at the beginning, you can easily change your
  119. strategy half way through without throwing out all your code. To
  120. demonstrate this, I incorporated both methods in a single source code
  121. set.
  122.  
  123. A preprocessor directive is used to distinguish between the mode X
  124. code and the mode 13h code. It is defined in the file DEFS.H, as 
  125. follows:
  126.  
  127. //#define ModeX
  128.  
  129. Uncomment this line to make the program run in mode X. Otherwise, it
  130. will default to mode 13h. There are just a few places where the
  131. preprocessor directive is used. For example:
  132.  
  133. #ifdef ModeX
  134.    fg_transfer(0,351,vpo,vpb,0,hpb,0,0);
  135. #else
  136.    fg_vbcopy(0,351,vpo,vpb,0,hpb,workvb,workvb);
  137. #endif
  138.  
  139. This means the mode X method requires a "transfer" from video memory
  140. to video momory, while the mode 13h method requires a virtual buffer
  141. copy.  The coordinates are the same, only the source and destination
  142. change.
  143.  
  144. Another interesting place where the preprocessor directive is applied
  145. is in the function swap(). Originally, this function was supposed to
  146. simulate page flipping by moving the origin of the visual page. In
  147. the mode 13h method, it does the fast 32-bit blit from RAM to video
  148. memory as follows:
  149.  
  150. #ifdef ModeX
  151.    fg_pan(screen_orgx,screen_orgy+vpo);
  152. #else
  153.    x1 = screen_orgx;
  154.    x2 = x1+319;
  155.    y1 = screen_orgy+vpo;
  156.    y2 = y1+199;
  157.    fg_vbpaste(x1,x2,y1,y2,0,199);
  158. #endif
  159.  
  160. There are a few other places where the code differs between the two
  161. methods, especially in the initialization functions in the file
  162. LOADGAME.C.
  163.  
  164. Results
  165. -------
  166.  
  167. Results of the experiment are mixed. I still haven't decided which
  168. strategy is the best. If I were going to turn this into a game, I
  169. would choose the strategy based on other considerations, such as
  170. what sound library I planned to use. Not all sound libraries support
  171. protected mode. 
  172.  
  173. Here are the results I noticed:
  174.  
  175. Speed:
  176.  
  177. The mode 13h version is faster on my system. The mode X version
  178. would be faster, except that you have to wait for the vertical
  179. retrace. These results might be different on a slower computer,
  180. where the animation occurs slower than the retrace rate.
  181.  
  182. Flicker:
  183.  
  184. The mode 13h version barely flickers, even when there are
  185. no checks for the vertical retrace. The mode X version only
  186. flickers when the retrace is turned off. Note that the background
  187. artwork hides the flickering. That is, the sky and clouds lend
  188. themselves to a certain amount of flickering without loss of
  189. aesthetic quality. On a more clearly defined tile background (walls
  190. and platforms) flickering may be more pronounced.
  191.  
  192. Jumpiness:
  193.  
  194. In the mode X version, there is a barely-noticeable jump during the
  195. scroll when there are column and row rebuilds. On some systems this
  196. is worse than on others. The mode 13h version is smooth as silk.
  197. Note that the jumpiness is especially noticeable in this particular
  198. demo because it attempts to do continuous scrolling. Most games don't
  199. scroll continuously. They focus on a part of a level, where a sprite
  200. will run around and jump and shoot, and the scrolling is sporatic. In
  201. a game like that, the jumpiness would be hidden in the other motion.
  202.  
  203. Compatibility:
  204.  
  205. The mode 13h method uses 32-bit protected mode. That means it
  206. requires a 386 or better system with at least 2 megabytes of RAM.
  207. The EXE was built with Watcom C/C++ version 10, so it requires the
  208. Rational Systems DOS/4GW DOS extender run-time module (DOS4GW.EXE).
  209. The mode X version can be recompiled in real mode and run in under
  210. 512k.
  211.  
  212. Sprites:
  213.  
  214. The more sprites on the screen, and the larger they are, the more
  215. speed degradation you will see in the mode X version (because more
  216. tiles will need to be replaced each frame). In the mode 13h version,
  217. the size and number of sprites is almost irrelevant (because they are
  218. simply data moves in system RAM, which is very fast). I would expect
  219. a major speed degradation.
  220.  
  221. Speeding up the Virtual Buffers
  222. -------------------------------
  223.  
  224. I organized the graphics in RAM exactly the same way they were
  225. organized in video memory. That is, I allocated a virtual buffer
  226. exactly the same size as the resized video memory, and I built each
  227. frame by replacing dirty tiles. The data moves are much faster in RAM
  228. than in video memory, but there is still overhead involved in
  229. building a buffer from tiles. A quicker way to build screens would be
  230. to build the entire level at load time in a huge RAM array, and then
  231. just locate the part of the level you need for a screen and blit
  232. that. I believe this method would also simplify the code
  233. significantly. It would, however, require at least 4 megabytes of
  234. system RAM to work -- probably not unreasonable for modern games.
  235.  
  236. I haven't written the code to try that yet. I will probably start
  237. working on that soon.
  238.  
  239. Speeding up the Mode X method
  240. -----------------------------
  241.  
  242. The greatest overhead in building a screen from tiles comes from
  243. calculating the video memory locations for the source and destination
  244. of the tiles. This can be optimized by pre-calculating the tile
  245. locations, as done in the function fg_copytile(), found in the file
  246. COPYTILE.ASM. The assembly language source code is included with
  247. this distribution. To insert it into the Quickfire source code,
  248. link with COPYTILE.OBJ and replace the function put_tile() with
  249. this macro:
  250.  
  251. #define put_tile(i,j) copytile((int)backtile[i+tile_orgx][j+tile_orgy],i,j,hidden);
  252.  
  253. Don't use the copytile function in protected mode, it was written
  254. to work in real mode in the medium or large model.
  255.  
  256. Again, you will most likely only see a significant improvement on
  257. systems where the animation is slower than the vertical retrace rate.
  258. On a 386 or lower the speed boost will be more significant than on a
  259. 486 or higher. Try it and see.
  260.  
  261. Conclusions
  262. -----------
  263.  
  264. I believe this experiment proves conclusively that both methods work
  265. perfectly well for tile-based scrolling. The method to choose for a
  266. game depend on other factors, such as the type of game, the artwork,
  267. and the sound library.
  268.  
  269. Acknowledgements
  270. ----------------
  271.  
  272. I would like to thank Les Pardew of Cygnus Multimedia for contributing
  273. the artwork. I'd also like to thank everybody helped with this
  274. project, including (but not limited to) Ted Gruber, Mark Betz, Rob
  275. Wallace, John Ratcliff, and Karen Crowther.
  276.  
  277. For more information about Fastgraph contact:
  278. --------------------------------------------
  279.  
  280. Ted Gruber Software
  281. P.O. Box 13408
  282. Las Vegas, NV 89112
  283. (702) 735-1980 (voice)
  284. (702) 735-4603 (fax)
  285. (702) 796-7134 (bbs)
  286.  
  287. Internet:
  288. ftp.accessnv.com \fg for files
  289. 72000,1642@compuserve.com for email
  290. fastgraph@aol.com for flames <g>
  291.  
  292. Helpful forums:
  293. GO GAMEDEV on CompuServe
  294. rec.games.programmer in the Internet
  295.  
  296. To get the free Fastgraph/Light evaluation kit, just ask!
  297.  
  298.